package com.leon.datalink.core.persistence;

/**
 * 持久化功能验证程序
 */
public class PersistenceVerification {
    
    public static void main(String[] args) {
        System.out.println("=== DataLink Actor持久化功能验证 ===");
        
        try {
            // 设置测试配置
            System.setProperty("datalink.persistence.enabled", "true");
            System.setProperty("datalink.persistence.storage.path", "target/test-persistence");
            
            // 获取配置管理器实例
            PersistenceConfigManager manager = PersistenceConfigManager.getInstance();
            System.out.println("✓ PersistenceConfigManager实例创建成功");
            
            // 初始化配置管理器
            manager.initialize();
            System.out.println("✓ PersistenceConfigManager初始化成功");
            
            // 测试全局持久化开关
            boolean globalEnabled = manager.isGlobalPersistenceEnabled();
            System.out.println("✓ 全局持久化开关状态: " + globalEnabled);
            
            // 测试Actor类型持久化配置
            manager.setActorTypePersistence("com.leon.datalink.node.TestActor", true);
            System.out.println("✓ Actor类型持久化配置设置成功");
            
            // 测试持久化判断
            boolean shouldPersist = manager.shouldPersist("com.leon.datalink.node.TestActor", "test-node-001", null);
            System.out.println("✓ Actor持久化判断结果: " + shouldPersist);
            
            // 测试消息持久化判断
            boolean shouldPersistMessage = manager.shouldPersistMessage("test-node-001", "DataMessage");
            System.out.println("✓ 消息持久化判断结果: " + shouldPersistMessage);
            
            // 测试黑名单消息
            System.setProperty("datalink.persistence.message.blacklist", "HeartbeatMessage,PingMessage");
            boolean shouldPersistHeartbeat = manager.shouldPersistMessage("test-node-001", "HeartbeatMessage");
            System.out.println("✓ 心跳消息持久化判断结果(应为false): " + shouldPersistHeartbeat);
            
            // 测试实例级配置
            manager.setInstancePersistence("test-node-002", false);
            System.out.println("✓ 实例级持久化配置设置成功");
            
            System.out.println("\n=== 验证结果 ===");
            System.out.println("✓ 所有基础功能验证通过");
            System.out.println("✓ 持久化配置管理器工作正常");
            System.out.println("✓ 选择性持久化策略功能正常");
            System.out.println("✓ 消息过滤功能正常");
            
        } catch (Exception e) {
            System.err.println("✗ 验证过程中发生错误: " + e.getMessage());
            e.printStackTrace();
        } finally {
            // 清理测试配置
            System.clearProperty("datalink.persistence.enabled");
            System.clearProperty("datalink.persistence.storage.path");
            System.clearProperty("datalink.persistence.message.blacklist");
        }
        
        System.out.println("\n=== 验证完成 ===");
    }
}
